package com.lgl.scsapi.config;

import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 错误页面配置类
 */
@Component
public class ErrorPageConfig {
    /**
     * SpringBoot2.0以上版本WebServerFactoryCustomizer代替之前版本的
     * EmbeddedWebServerFactoryCustomizerAutoConfiguration
     * @return
     */
    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
        //第二种写法：java8 lambda写法
        return (factory -> {
            ErrorPage error400 = new ErrorPage(HttpStatus.BAD_REQUEST, "/userPages/errorPages/400.html");
            ErrorPage error404 = new ErrorPage(HttpStatus.NOT_FOUND, "/userPages/errorPages/404.html");
            ErrorPage error500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/userPages/errorPages/500.html");
            factory.addErrorPages(error400,error404,error500);
        });
    }

}